import React, { Component } from 'react'
import Tab from './../../components/common/TabVertical'
import Content from './../../components/common/Content'
import Page from './../../components/common/Page'
import Empty from './../../components/common/Empty'
// import Crumbs from './../../components/common/Crumbs/index.jsx'
import styles from './Activity.module.scss'
import api from './../../serve/api'
import { withRouter } from 'react-router-dom'

class Activity extends Component {

  constructor(props) {
    super(props)
    this.state = {
      types: [],
      activities: [],
      orgId: '',
      pageTotal: '',
      page: 1,
      pageSize: 15,
      selected: 0
    }
  }
  
  onTab(item, index) {
    console.log(index)
    this.setState({
      selected: index,
      // typeId: item.id
    })
    // this.getHotNews(item.id, 1)
  }

  getCurrentPage(currentPage) {
    this.getOrgDynamic(this.state.typeId, currentPage)
  }

  componentDidMount() {
    const { match } = this.props
    const orgId = match.params.id
    this.getOrgDynamic(orgId, this.state.page)
  }

  // async getHotNewsTypeAll() {
  //   const data = await api.fetchListHotNewsTypeAll()
  //   if (data && data.code === '000000') {
  //     this.setState({
  //       types: data.result
  //     })
  //     if (data.result.length > 0) {
  //       const first = data.result[0]
  //       this.getOrgDynamic(first.id, this.state.page)
  //     }
  //   }
  // }

  async getOrgDynamic(orgId, page) {
    const data = await api.listOrgDynamic({ orgId, page, pageSize: this.state.pageSize })
    if (data && data.code === '000000') {
      this.setState({
        page,
        orgId,
        activities: data.result || [],
        pageTotal: data.resultNum
      })
    }
  }

  onItem(item) {
    this.props.history.push(`/mainPage/commonDetail/OrgDynamic/${item.id}`)
  }

  render() {
    const { activities, page, pageTotal } = this.state
    return (
      <div className={styles.company_activity_container_bg}>
        <div className={styles.company_activity_container}>
          {activities.length === 0 && <Empty title="暂无数据" />}
          {activities.length > 0 && <Content datas={activities} onItem={item => this.onItem(item)} />}
          {activities.length > 0 && <Page 
            pageConfig={{totalPage: pageTotal, pageSize: this.state.pageSize, currentPage: page }}
            pageCallbackFn={currentPage => this.getCurrentPage(currentPage)}
          />}
        </div>
      </div>
    )
  }
}
export default withRouter(Activity)
